package com.windgo.controller.admin;

import com.windgo.bean.MarketAd;
import com.windgo.bean.common.BasePageInfo;
import com.windgo.bean.common.BaseRespVo;
import com.windgo.bean.common.CommonData;
import com.windgo.service.AdService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author:ZhouXin
 * @Date:2022/10/12 21:00
 * @Description:
 **/
@RestController
@RequestMapping("admin/ad")
public class AdController {
    @Autowired
    AdService adService;


    /**
     * 显示所有广告信息
     * @param info
     * @param name
     * @param content
     * @return
     */
    @GetMapping("list")
    @RequiresPermissions("perms[admin:ad:list]")
    public BaseRespVo list(BasePageInfo info,String name,String content){
        CommonData<MarketAd> data=adService.list(info,name,content);
        return BaseRespVo.ok(data);
    }


    /**
     * 新增广告
     * @param marketAd
     * @return
     */
    @PostMapping("create")
    @RequiresPermissions("perms[admin:ad:create]")
    public BaseRespVo create(@RequestBody MarketAd marketAd){
        MarketAd marketAd1=adService.create(marketAd);
        return BaseRespVo.ok(marketAd1);
    }


    /**
     * 修改广告信息
     * @param marketAd
     * @return
     */
    @PostMapping("update")
    @RequiresPermissions("perms[admin:ad:update]")
    public BaseRespVo update(@RequestBody MarketAd marketAd){
        MarketAd marketAd1=adService.update(marketAd);
        return BaseRespVo.ok(marketAd1);
    }

    @PostMapping("delete")
    @RequiresPermissions("perms[admin:ad:delete]")
    public BaseRespVo delete(@RequestBody MarketAd marketAd){
        Integer id = marketAd.getId();
        adService.delete(id);
        return BaseRespVo.ok();
    }


}